/* smw.h
 * Structs, typedefs, etc specific to SMW
 */
#ifndef __newmoon_smw_h
#define __newmoon_smw_h

#define EMPTY_BLOCK 0x25 //block used to fill empty areas of Map16
#define MAX_SCREENS 32 //Maximum screens per level
#define NUM_TILESETS 15 //Number of valid tilesets

//Macros to extract info from tilemaps
#define TILE_ID_BITS 0x3FF
#define TILE_PALETTE_BITS 0x1C00
#define TILE_PRIORITY_BITS 0x2000
#define TILE_XFLIP_BITS 0x4000
#define TILE_YFLIP_BITS 0x8000
#define TILE_ID(d) ((d) & TILE_ID_BITS)
#define TILE_PALETTE(d) (((d) & TILE_PALETTE_BITS) >> 10)
#define TILE_PRIORITY(d) (((d) & TILE_PRIORITY_BITS) >> 13)
#define TILE_XFLIP(d) (((d) & TILE_XFLIP_BITS) >> 14)
#define TILE_YFLIP(d) (((d) & TILE_YFLIP_BITS) >> 15)

//Macros to extract colour elements from SNES colours
#define RED(c) (BITS((c), 0, 4) << 3)
#define GREEN(c) (BITS((c), 5, 9) << 3)
#define BLUE(c) (BITS((c), 10, 14) << 3)

//Compression formats
typedef enum {
	COMP_NONE = 0, //no compression
	COMP_3BPP,
	COMP_LZ2,
	COMP_3BPP_LZ2
} CompressionFormat;

//These are the low-level defines used in the ROM.
typedef struct {
	union {
		u8 Byte[5];
		struct {
			u8 BGPal : 3;
			u8 NumScreens : 5;
			u8 BGCol : 3;
			u8 Mode : 5;
			u8 Layer3Priority : 1;
			u8 Music : 3;
			u8 Spriteset : 4;
			u8 Time : 2;
			u8 SprPal : 3;
			u8 FGPal : 3;
			u8 ItemMem : 2;
			u8 VScroll : 2;
			u8 Tileset : 4;
		};
	};
} SMWLevelHeader;

typedef struct {
	//union {
		u8 Byte[4];
		struct {
			u8 NewScreen : 1;
			u8 ObjIDHigh : 2;
			u8 YPos : 5;
			u8 ObjIDLow : 4;
			u8 XPos : 4;
			u8 Settings;
			u8 Dest; //Destination level, for screen exit objects only.
			//All other objects are 3 bytes.
		};
	//};
} RawSMWObject;

#endif //__newmoon_smw_h
